<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin: 0;padding:0;box-sizing: border-box}
        html, body, .container{
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div class="container">
        <canvas id="cns"></canvas>
    </div>

    <script>
        //1. 获取元素
        let canvas = document.querySelector("#cns");
        //2. 设置宽度与高度
        canvas.width = document.documentElement.clientWidth;
        canvas.height = document.documentElement.clientHeight;
        //3. 创建画布对象
        const ctx = canvas.getContext('2d');

        //触摸开始事件
        canvas.addEventListener('touchstart', function(e){
            //开始回调
            ctx.beginPath();
            //移动画笔
            let {pageX, pageY} = e.changedTouches[0];
            ctx.moveTo(pageX, pageY);
            //阻止默认行为
            e.preventDefault();
        })
        //触摸滑动事件
        canvas.addEventListener('touchmove', function(e){
            //画线
            let {pageX, pageY} = e.changedTouches[0];
            ctx.lineTo(pageX, pageY);
            //描边
            ctx.stroke();
        })
        //触摸结束事件
        canvas.addEventListener('touchend', function(e){})





    </script>
</body>
</html>